home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Info-Mac 1992 August
/
info-mac-1992.iso
/
Applications (app)
/
Image 1.44
/
Macros
/
Measurement Macros
< prev
next >
Wrap
Text File
|
1992-03-26
|
6KB
|
293 lines
macro 'Count Particles at Random Locations';
var
n,i,width,height,PicID,nLocations:integer;
size:real;
begin
RequiresVersion(1.44);
nLocations:=10;
size:=0.25;
n:=1;
GetPicSize(width,height);
PicID:=PicNumber;
SetUser1Label('Count');
SetOptions('User1');
for i:=1 to nLocations do begin
SelectPic(PicID);
MakeRoi((1-size)*width*random,(1-size)*height*random,size*width,size*height);
Duplicate('Temp');;
SetDensitySlice(255,255);
AnalyzeParticles;
Dispose;
rUser1[i]:=rCount;
end;
KillRoi;
SetCounter(nLocations);
ShowResults;
end;
macro 'Make Circle from Line';
var
x1,x2,y1,y2,top,left,width,height:integer;
xcenter,ycenter,radius:integer;
begin
GetLine(x1,y1,x2,y2,width);
if x1<0 then begin
PutMessage('This macro requires a line selection.');
exit;
end;
xcenter:=x1+(x2-x1)/2;
ycenter:=y1+(y2-y1)/2;
radius:=sqrt(sqr(x2-x1)+sqr(y2-y1))/2;
MakeOvalROI(xcenter-radius,ycenter-radius,radius*2,radius*2);
end;
macro 'Display Calibration Table';
{
Stores 0-255(all possible gray values) in the User1 column
and the 256 corresponding calibrated values in the User2 column.
Max Measurements must be set to 256 or greater. Use the Export
command to export the calibration table to a text file. The two
columns will be identical if the image is not calibrated.
}
var
i:integer;
v:real;
begin
RequiresVersion(1.44);
SetCounter(256);
SetUser1Label('value');
SetUser2Label('cvalue');
for i:=0 to 255 do begin
rUser1[i+1]:=i;
rUser2[i+1]:=cvalue(i);
end;
ShowResults;
end;
macro 'Measure and draw line [L]';
var
x1,x2,y1,y2,width:integer;
begin
GetLine(x1,y1,x2,y2,width);
if x1<0 then begin
PutMessage('This macro requires a line selection.');
exit;
end;
Measure;
Fill;
KillRoi;
end;
macro 'Measure All';
{Measures all currently open images using the current selection. There is}
{an implied "Select All" if the active image doesn't have a selection.}
var
i,left,top,width,height:integer;
begin
ResetCounters;
for i:=1 to nPics do begin
SelectPic(i);
RestoreROI;
Measure;
end;
end;
macro 'Measure All from Disk';
{
Reads from disk and measures a set of images too large to simultaneously
fit in memory. The image names names must be in the form '01', '02', etc.
Before starting, open and outline the first image('01').
}
var
i,width,height:integer;
begin
GetPicSize(width,height);
if width=0 then begin
PutMessage('Before running this macro, open and outline the first image("01") in the series.');
exit;
end;
ResetCounters;
Measure;
close;
for i:=2 to 1000 do begin
open(i:2);
RestoreROI;
Measure;
close;
end;
end;
macro 'Paste Results [P]'
{Use the Measure command, the ruler tool, or the pointing tool to}
{make up to about 10 measurements, then use this macro to paste}
{the results into the upper left corner of the window.}
begin
SetFont('Monaco');
SetFontSize(9);
SetText('Plain; Align Left');
SetOption; {Copy headings}
CopyResults;
MakeRoi(-10,0,250,150);
Paste;
KillRoi;
ResetCounter;
end;
macro 'Measure Redirected and Label'
begin
Redirect(true);
Measure;
Redirect(false);
MarkSelection;
RestoreRoi;
end;
macro 'Reset Measurement Options';
{Resets the Options dialog box in the Analyze menu to the default settings.}
begin
RequiresVersion(1.44);
SetOptions('Area; Mean');
Redirect(false);
LabelParticles(true);
OutlineParticles(false);
IgnoreParticlesTouchingEdge(false);
IncludeInteriorHoles(false);
WandAutoMeasure(false);
AdjustAreas(false);
SetParticleSize(1,999999);
SetPrecision(2);
end;
macro 'Set Threshold';
var
lower,upper:integer;
begin
lower:=GetNumber('Lower:',1);
upper:=GetNumber('Upper:',254);
SetDensitySlice(lower,upper);
end;
macro 'Measure Accumulated Perimeter[A]';
{
Measures perimeter and computes accumulated perimeter,
storing it in the User1 column.
}
var
i:integer;
Total:real;
begin
MeasurePerimeter(true);
SetOptions('Area; Mean; Perimeter; User1');
SetUser1Label('Total');
Measure;
Total:=0;
for i:=1 to rCount do Total:=Total+rLength[i];
rUser1[rCount]:=Total;
UpdateResults;
end;
macro 'Count Black and White Pixels [B]';
{
Counts the number of black and white pixels in the current
selection and stores the counts in the User1 and User2 columns.
}
begin
RequiresVersion(1.44);
SetUser1Label('Black');
SetUser2Label('White');
Measure;
rUser1[rCount]:=histogram[255];
rUser2[rCount]:=histogram[0];
UpdateResults;
end;
macro 'Compute Average and Total Area [T]';
{
Computes average and accumulated area and stores
the them in the Major and Minor Axis columns.
}
var
i:integer;
sum:real;
begin
RequiresVersion(1.44);
SetUser1Label('Avg');
SetUser2Label('Total');
SetOptions('Area; User1; User2');
Measure;
sum:=0;
for i:=1 to rCount do sum:=sum+rArea[i];
rUser1[rCount]:=sum/rCount;
rUser2[rCount]:=sum;
UpdateResults;
end;
macro 'Measure Circularity [C]';
begin
SetUser1Label('Shape');
Measure;
rUser1[rCount]:=4*3.14159265*(rArea[rCount]/sqr(rLength[rCount]));
UpdateResults;
end;
macro 'Fit Ellipse and Draw in White';
var
left,top,width,height:real;
begin
GetRoi(left,top,width,height);
if width=0 then begin
PutMessage('This macro requires a selection.');
exit;
end;
SetOptions('Area; Mean; X-Y Center');
Measure;
SetOption; MarkSelection;
KillRoi;
SelectAll;
KillRoi;
end;
macro 'Draw XY Center';
var
left,top,width,height,x,y:real;
begin
RequiresVersion(1.44);
GetRoi(left,top,width,height);
if width=0 then begin
PutMessage('This macro requires a selection.');
exit;
end;
SaveState; {Invert Y status saved starting with V1.44b21}
InvertY(false);
SetForegroundColor(255); {black}
SetOptions('Area; Mean; X-Y Center'); {XY Center}
Measure;
KillRoi;
x:=rX[rCount];
y:=rY[rCount];
MoveTo(x-5,y);
LineTo(x+5,y);
MoveTo(x,y-5);
LineTo(x,y+5);
RestoreState;
end;